The present invention generally relates to computer program compilers and program execution environments, and more particularly to processing statements of one language embedded in a program written in another language.
Some compilers and database management systems, for example, the UCS and RDMS systems from Unisys Corporation, support SQL statements embedded in programs of various languages. For example, many application programs are written in the COBOL programming language and have embedded therein SQL statements that reference a database. Embedded SQL statements allow an application programmer to use SQL techniques and SQL-compatible database management systems in combination with COBOL application programs, for example.
The example UCS and RDMS systems have the capability to compile application programs having embedded SQL statements. Continuing the example having SQL statements embedded in a COBOL program, a COBOL compiler compiles the COBOL statements, and when an SQL statement is encountered, the SQL statement is passed to a compile-time component of RDMS. RDMS resolves the data object names in the SQL statement and creates an execution sequence that optimizes execution of the SQL statement. The resolved names and execution sequence for the SQL statement are saved and combined with the executable program produced in compiling the COBOL code. When an SQL statement is encountered during execution of the compiled program, the resolved names and execution sequence associated with the SQL statement are provided to the runtime component of RDMS for execution.
Having compiled SQL statements offers the advantage of fast execution as compared to interpreted SQL statements. However, interpreted SQL offers increased flexibility in maintaining the program. For example, when changes are made to database definitions, interpreted SQL statements do not need to be recompiled. If the changes in database definition are compatible with the SQL statements, the program can be executed without compilation. However, with compiled SQL statements that are embedded in a program, the program must be recompiled. Since the compilation of embedded SQL statements is performed as an integral part of compiling the application program, the effort required to build a new application with respect to the changed database definitions can be time-consuming. A method that addresses the aforementioned problems, as well as other related problems, is therefore desirable.
A computer-implemented method for processing statements of a first language embedded in a program having statements of a second language is provided in one embodiment. The method comprises compiling statements of the first and second languages into an executable program, the executable program including original executable instructions associated with the statements of the first language. The executable program is executed, and during execution, recompilation conditions are detected for statements of the first language. In response to the recompilation conditions, selected statements of the first language are recompiled into new executable instructions during execution of the executable program. The new executable instructions are respectively associated with the selected statements and are executed in place of the original executable instructions.
In another embodiment, a system is provided for processing statements of a first language embedded in a program having statements of a second language. The system includes a compiler arrangement, a runtime arrangement, and a database management system. The compiler arrangement is configured to compile statements of the first and second languages into an executable program, the executable program including original executable instructions associated with the statements of the first language. The runtime arrangement is configured to execute the executable program. The database management system is coupled to the runtime arrangement, and is configured to detect recompilation conditions for statements of the first language during execution of the executable program. In response to the recompilation conditions, selected statements of the first language are recompiled into new executable instructions during execution of the executable program, and the new executable instructions are respectively associated with the selected statements. The database management system executes the new executable instructions in place of the original executable instructions.
In accordance with another example embodiment of the invention, there is provided a computer program product that is configured to process statements of one language embedded in a program of another language, as summarized above.